
var TAB_DATA={noOfResults:0};
var TAB_DATA_GRAPH={noOfGraphs:0};
$(document).ready(function() {
	 $("#tabs").tabs();
	 hideResults(); 
	 $('form').submit(function() {
		 $(".error").hide();
		 var bankIds = $("#bankIds").val();
		 if(bankIds != null && bankIds.length > 1 && $("#factors_id").val() != null && $("#fromDt").val() != "" && $("#toDt").val() != ""){
			  //alert($(this).attr('action')+'?'+$(this).serialize()); 
			//  $("#graph-iframe-1").attr('src',contextRoot+'/search/graph.html'+'?'+$(this).serialize());
			  if($("#columnarForm").find("input[type='submit']:focus").val() == "Result View"){
			  	TAB_DATA.noOfResults= TAB_DATA.noOfResults+1;
			  	if( TAB_DATA.noOfResults>4){
				  //reset to first tab
				  TAB_DATA.noOfResults=1;
				}
var resultArray = document.getElementsByName("result-iframe-"+TAB_DATA.noOfResults);				
			  	$(resultArray).attr('src',contextRoot+'/search/result.html'+'?'+$(this).serialize());
		 		$("#tabs").tabs('select', TAB_DATA.noOfResults);
		 		$("#tab-result-"+TAB_DATA.noOfResults).css("display","list-item");
		 	  }else {
		 		 TAB_DATA_GRAPH.noOfGraphs= TAB_DATA_GRAPH.noOfGraphs+1;		 		 
				  	if( TAB_DATA_GRAPH.noOfGraphs>4){
					  //reset to first tab
				  		TAB_DATA_GRAPH.noOfGraphs=1;
					}
var graphArray = document.getElementsByName("graph-iframe-"+TAB_DATA_GRAPH.noOfGraphs);				
					
				  	$(graphArray).attr('src',contextRoot+'/search/graphdummy.html'+'?'+$(this).serialize());
			 		$("#tabs").tabs('select', TAB_DATA_GRAPH.noOfGraphs+4);
			 		$("#tab-graph-"+TAB_DATA_GRAPH.noOfGraphs).css("display","list-item");	 		  
		 	  }
			  return false;
	 	}else if (bankIds != null && bankIds.length == 1){
			$("#validation")
			.after(
					'<span class="error" style="color: red">Please choose atleast two banks to compare.</span>');
			return false;	 		
	 	}
		else{
			$("#validation")
			.after(
					'<span class="error" style="color: red">Please choose atleast one value in all fields.</span>');
			return false;	 		
	 	}
	 });	 
	 $(".showComments").click(function(){ 
			var fieldComment = '#'+$(this).attr('id')+'hidden';
			$("#communicationLogMessage").attr('enabled', true);
			var fieldCommentValue = $(fieldComment).val();
			$("#communicationLogMessage").html(fieldCommentValue);
			$("#communicationLogMessage").attr('readonly','readonly');
		});
});

function hideResults(){
	
	 $("#tab-result-1").css("display","none");
	 $("#tab-result-2").css("display","none");
	 $("#tab-result-3").css("display","none");
	 $("#tab-result-4").css("display","none");
	 $("#tab-graph-1").css("display","none");
	 $("#tab-graph-2").css("display","none");
	 $("#tab-graph-3").css("display","none");
	 $("#tab-graph-4").css("display","none");	 
}

function PrintContent()
{
	var DocumentContainer = document.getElementById('printDiv');
	var WindowObject = window.open("", "PrintWindow",
	"width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
	WindowObject.document.writeln(DocumentContainer.innerHTML);
	WindowObject.document.close();
	WindowObject.focus();
	WindowObject.print();
	WindowObject.close();
}